<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\wxapp\controller;

use api\wxapp\controller\ApiBaseController;
use think\Db;
use api\wxapp\model\Like;
class LikeController extends ApiBaseController
{
    public function index()
    {
        $params = $this->getParam();
        $this->checkuid($params);
        $this->checkgoodsId($params);
        !isset($params['type']) ? $this->error('参数缺失!!!!') : '';
        // type = 1 好赞  2 差赞 3 取消赞
        $where = array();
        $where[] = ['uid','eq',$params['uid']];
        $where[] = ['goods_id','eq',$params['goods_id']];
        $find = Like::where($where)->find();
        if($find){
            $res = Like::where('id',$find['id'])->update(array('type'=>$params['type']));
        }else{
            $params['addtime'] = $this->returnDateTime();
            $res = Like::insertGetId($params);
        }
        if($res){
            $this->success('请求成功!',$res);
        }else{
            $this->success('执行失败!',$res);
        }
    }
}
